<template>
  <div class="home">
    <h2>欢迎{{ formatusername }}</h2>
    <button @click="logout">注销</button>
  </div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue'
import router from "../router";
import { mapGetters } from "vuex";

export default {
  name: "Home",
  components: {},
  data() {
    return {
      routes: router.options.routes,
    };
  },
  computed: {
    ...mapGetters(["formatusername"]),
  },
  methods: {
    gotoposts() {
      this.$router.push({
        // path:'/profile/posts'
        name: "Posts",
        query: { plan: "private" },
        params: {
          id: 100,
          name: "zhang",
        },
      });
    },
    goto(name) {
      console.log(name);
      this.$router.push({ name });
    },
    logout() {
      // 假注销  真注销
      localStorage.removeItem("token");
      this.$store.commit("setToken", "");
      this.$router.push({
        name: 'Login'
      })
    },
  },
  created() {
    // 并不是在这里取用户信息
    console.log(router.options.routes);
  },
};
</script>

<style lang="less" scoped>
header {
  border: 1px solid #000;
  height: 120px;
}
.container {
  display: flex;
  min-height: 500px;
}
.sideBar {
  width: 350px;
  // background: red;
  border: 1px solid #000;
}
.content {
  flex: 1;
  background: green;
}
footer {
  height: 120px;
  background: blue;
}

a {
  margin: 0 10px;
}
</style>
